<template>
	<view>
		<!-- 图标 -->
		<view style="margin-top: 30%;">
			租房
		</view>
		<view style="padding: 40rpx 80rpx;font-size: 35rpx;" class="box">
			<view>
				<u-button type="primary" size="large " open-type="getPhoneNumber" shape="circle" color="#28C445"
					@click="wwxlogin()">
					<i class="icon vx"></i>
					微信快捷登录
				</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import code from '../../uni_modules/uview-ui/libs/config/props/code';
	import {mapMutations } from 'vuex'
	export default {
		data() {
			return {
				code: '',
				AccessToken: '',
				phonecode: '',
				openid: '',
				img:"",
			};
		},
		methods: {
			...mapMutations(['login']),
			wwxlogin() {
				this.getcode()
				wx.getUserProfile({
					desc: '用于完善会员资料',
					success: res => {
						this.img = res.userInfo.avatarUrl
						if (this.openid) {
							this.getuser()
						}
					},
					fail: res => {
						console.log("失败", res);
					}
				})
			},
			getcode() {
				wx.login({
					success: res => {
						console.log(res.code)
						if (res.code) {
							//发起网络请求
							this.code = res.code
							uni.request({
								method: 'POST',
								header: {
									'content-type': "application/json",
								},
								url: this.websiteUrl + 'TN-INDEX/house/wx/getCode?code=' + res.code,
								success: esc => {
									this.openid = esc.data.data.openID
									console.log(this.openid)
								}
							})
						} else {
							console.log('登录失败！' + res.errMsg)
						}
					}
				})
			},
			gotoPhonelogin() {
				uni.navigateTo({
					url: "/pages/login/phonelogin/phonelogin"
				})
			},
			gotoHome() {
				uni.reLaunch({
					url: "/pages/home/home"
				})
			},
			getuser() {
				uni.request({
					url: "http://172.18.48.131:9527/TN-USER/user/wx/getuser?openid=" + this.openid,
					success: res => {
						if (res.data.openID != null) {
							console.log(res.data)
							
							//保存用户信息
							this.login(res.data)
							
							uni.reLaunch({
								url: "/pages/home/home"
							})
						} else {
							uni.navigateTo({
								url: "/pages/login/phonelogin/phonelogin",
								success: esc => {
									esc.eventChannel.emit('argParams', {
										openid : this.openid,
										img : this.img
									})
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";

	.icon {
		background-size: cover;
		width: 80rpx;
		height: 80rpx
	}

	.vx {
		background-image: url("data:image/svg+xml,%3Csvg t='1689645074652' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='5030' width='200' height='200'%3E%3Cpath d='M777 577.8c23.8 0 39.7-15.7 39.7-31.7 0-15.8-15.9-31.7-39.7-31.7-15.7 0-31.5 15.9-31.5 31.7-0.1 16 15.8 31.7 31.5 31.7z m-174.5 0c24 0 39.7-15.7 39.7-31.7 0-15.8-15.7-31.7-39.7-31.7-15.8 0-31.7 15.9-31.7 31.7 0 16 15.9 31.7 31.7 31.7z m356.8 39.6c0 71.5-47.4 134.8-111.1 182.6l23.9 79.3-87-47.6c-31.7 8-63.6 15.9-95.1 15.9-150.9 0-269.7-103.1-269.7-230.1 0-126.7 118.8-230 269.7-230 142.5-0.1 269.3 103.2 269.3 229.9zM499.4 363.6c23.9 0 39.7-15.9 39.7-39.7 0-23.9-15.8-39.6-39.7-39.6-23.8 0-47.6 15.7-47.6 39.6 0 23.8 23.8 39.7 47.6 39.7z m-222 0c23.8 0 39.6-15.9 39.6-39.7 0-23.9-15.8-39.6-39.6-39.6s-47.8 15.7-47.8 39.6c0.1 23.8 24.1 39.7 47.8 39.7z m103.1-214.1c155.9 0 292.5 94.9 320 222.7-10.1-1.1-20.3-1.9-30.5-1.9-150.6 0-269.6 112.4-269.6 250.9 0 23 3.6 45.2 9.8 66.4-9.8 0.8-19.7 1.3-29.6 1.3-39.6 0-71.4-8.1-111.1-15.9l-110.9 55.6 31.7-95.4c-79.4-55.4-126.9-126.9-126.9-214-0.1-150.9 142.7-269.7 317.1-269.7z' fill='%23ffffff' p-id='5031'%3E%3C/path%3E%3C/svg%3E");
	}

	.phone {
		background-image: url("data:image/svg+xml,%3Csvg t='1689647617355' class='icon' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='3474' width='100' height='100'%3E%3Cpath d='M692.1 61H331.9c-43.9 0-79.7 35.7-79.7 79.7v753.1c0 43.9 35.7 79.7 79.7 79.7h360.3c43.9 0 79.7-35.7 79.7-79.7V140.7c-0.1-43.9-35.8-79.7-79.8-79.7z m50.7 832.8c0 27.9-22.7 50.7-50.7 50.7H331.9c-27.9 0-50.7-22.7-50.7-50.7V140.7c0-27.9 22.7-50.7 50.7-50.7h360.3c27.9 0 50.7 22.7 50.7 50.7v753.1z' fill='%23d81e06' p-id='3475'%3E%3C/path%3E%3Cpath d='M682.1 190.8H341.9c-16.1 0-29.2 13.1-29.2 29.2v547.5c0 16.1 13.1 29.2 29.2 29.2h340.2c16.1 0 29.2-13.1 29.2-29.2V219.9c0-16.1-13.1-29.1-29.2-29.1z m0.2 576.7c0 0.1-0.1 0.2-0.2 0.2l-340.4-0.2 0.2-547.7 340.4 0.2v547.5zM449.2 154.9h125.6c8 0 14.5-6.5 14.5-14.5s-6.5-14.5-14.5-14.5H449.2c-8 0-14.5 6.5-14.5 14.5s6.5 14.5 14.5 14.5zM512 823.9c-26 0-47.2 21.2-47.2 47.2 0 26 21.2 47.2 47.2 47.2 26 0 47.2-21.2 47.2-47.2 0-26-21.2-47.2-47.2-47.2z m0 65.4c-10 0-18.2-8.2-18.2-18.2s8.2-18.2 18.2-18.2 18.2 8.2 18.2 18.2-8.2 18.2-18.2 18.2z' fill='%23d81e06' p-id='3476'%3E%3C/path%3E%3C/svg%3E");
	}
</style>